package xcmg.device.infra;

import org.apache.commons.collections.CollectionUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/** 
* @Desc   excel工具类
* @Author Mr.dong 
* @Date   2021/5/13 17:25
*/ 
public class EasyExcelUtil {

    public static SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");

    public static void prepareResponse(HttpServletResponse response, String downloadName) throws UnsupportedEncodingException {
        response.setCharacterEncoding("utf-8");
        // 这里URLEncoder.encode可以防止中文乱码 当然和easyExcel没有关系
        String exportName = "Excel-" + format.format(new Date()) + downloadName;
        String fileName = URLEncoder.encode(exportName, "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        response.setContentType("application/x-msdownload");
    }
}
